<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>新增轮播图</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/layui/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="/layui/css/public.css" media="all">
  <style>
    body {
      background-color: #ffffff;
    }
  </style>
</head>
<body>
<div class="layui-form layuimini-form">

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">上传轮播图</label>
    <div class="layui-input-block">
      <button type="button" name="imagePath" class="layui-btn" id="imagePath">
        <i class="layui-icon">&#xe67c;</i>上传图片
      </button>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label required">跳转方式</label>
    <div class="layui-input-block">
      <input type="text" name="url" lay-verify="required" lay-reqtext="跳转方式不能为空" placeholder="请输入跳转方式" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label required">排序</label>
    <div class="layui-input-block">
      <input type="text" name="sort" lay-verify="required" lay-reqtext="排序不能为空" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label required">备注</label>
    <div class="layui-input-block">
      <input type="text" name="descs" lay-verify="required" lay-reqtext="备注不能为空" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label required">状态</label>
    <div class="layui-input-block">
      <input type="radio" name="status" value="1" title="开启">
      <input type="radio" name="status" value="2" title="关闭">
    </div>
  </div>
<%--  新增时间的隐藏--%>
<%--  <input type="hidden" name="createTime" id="createTime">--%>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认新增</button>
    </div>
  </div>
</div>
<script src="/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<%--时间转换--%>
<%--<script>--%>
<%--  Date.prototype.format = function (fmt) {--%>
<%--    var o = {--%>
<%--      "y+": this.getFullYear, //年--%>
<%--      "M+": this.getMonth() + 1, //月份--%>
<%--      "d+": this.getDate(), //日--%>
<%--    };--%>
<%--    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));--%>
<%--    for (var k in o)--%>
<%--      if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));--%>
<%--    return fmt;--%>
<%--  }--%>
<%--  document.getElementById('createTime').value = (new Date()).format('yyyy-MM-dd');--%>
<%--</script>--%>
<script>
  layui.use(['form', 'upload', 'layedit'], function () {
    var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            layedit = layui.layedit,
            $ = layui.$;



    // 上传图片
    var uploadInst = upload.render({
      elem: '#imagePath', //绑定元素
      url: '/operating/files', //上传接口
      done: function(res){
        //上传完毕回调
        layer.msg('上传成功');
      },
      error: function(){
        //请求异常回调
        layer.msg('上传失败，未知错误');
      }
    });

    //监听提交
    form.on('submit(saveBtn)', function (data) {

      $.ajax({
        url: '/operating/save',
        type: 'post',
        data: JSON.stringify(data.field),
        contentType: 'application/json',
        dataType: 'json',
        success: function (result) {
          if (result.code == '0') {
            // 关闭弹出层
            layer.close();
            // 刷新上一层页面
            parent.window.location.reload();
          }
        }
      });
      return false;
    });
  });
</script>
</body>
</html>